// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import fastClick from 'fastclick'
import 'babel-polyfill'
import 'stylus/index.styl'
import VueAwesomeSwiper from 'vue-awesome-swiper'
import 'swiper/dist/css/swiper.css'
import store from './store/index'
import VueLazyLoad from 'vue-lazyload'
import api from './api/index'
import VideoPlayer from 'vue-video-player'
import Cookies from 'js-cookie'
import VueAMap from 'vue-amap'
import {
  getLocalStorage,
  setLocalStorage,
  removeLocalStorage
} from '@/assets/js/localStorage'
import {
  isLogin
} from '@/assets/js/isLogin'
import {
  Picker,
  DatetimePicker,
  Popup,
  Cell,
  CellGroup,
  RadioGroup,
  Radio,
  PullRefresh,
  Checkbox,
  CheckboxGroup,
  Rate
} from 'vant'

require('video.js/dist/video-js.css')
require('vue-video-player/src/custom-theme.css')

Vue.config.productionTip = false
fastClick.attach(document.body)
Vue.use(VueAwesomeSwiper)
Vue.use(VueLazyLoad, {
  loading: require('@/assets/images/loading.png')
})
Vue.use(Picker).use(DatetimePicker).use(Popup).use(VueAMap).use(Cell).use(CellGroup).use(RadioGroup).use(Radio).use(PullRefresh).use(Checkbox).use(CheckboxGroup).use(Rate)
VueAMap.initAMapApiLoader({
  // 申请的高德key
  key: '1ffde01af34554d0ba5fbbb4eb3a0eb9',
  // 插件集合
  plugin: ['AMap.Geolocation', 'AMapManager', 'AMap.PlaceSearch']
})
Vue.prototype.$api = api
Vue.prototype.$Cookies = Cookies
Vue.prototype.$localStorage = {
  get: getLocalStorage,
  set: setLocalStorage,
  remove: removeLocalStorage
}
Vue.use(VideoPlayer)
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: {
    App
  },
  template: '<App/>'
})

router.beforeEach((to, from, next) => {
  if (to.path === '/reserve' || to.path === '/me/collect' || to.path === '/me/evaluate' || to.path === '/me/vcard') {
    isLogin(to.fullPath, next)
  } else {
    next()
  }
})
